import java.util.ArrayList;
import java.util.Calendar;



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ControllerInterface.java
 *
 * Created on 14-Mar-2012, 10:14:31
 */


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ControllerInterface.java
 *
 * Created on 14-Mar-2012, 10:14:31
 */

/**
 *
 * @author higgina0
 */
public class ControllerInterface extends javax.swing.JFrame 
{
    public ControllerInterface() {
        initComponents();
        //this.timetable = timetable;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        generateTimetableButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        generateTimetableButton.setText("Generate Timetable");
        generateTimetableButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                generateTimetableButtonActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 1, 13));
        jLabel1.setText("Welcome Controller");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(35, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(237, 237, 237))
            .addGroup(layout.createSequentialGroup()
                .addGap(137, 137, 137)
                .addComponent(generateTimetableButton)
                .addContainerGap(146, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(generateTimetableButton)
                .addContainerGap(30, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void generateTimetableButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateTimetableButtonActionPerformed
        ArrayList<ArrayList<DriverShift>> shifts;
        Roster r = new Roster();
        Calendar start = r.getStartDate();
        shifts = r.generateRoster();
        TimetableGeneratorInterface interfaceRoster = new TimetableGeneratorInterface(start, shifts);
        interfaceRoster.setVisible(true);

        /*Thread t = new Thread(r);
        t.start();
        progress = r.getProgress();
        jProgressBar.setValue(progress);
        jProgressBar.repaint();      */
    }//GEN-LAST:event_generateTimetableButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        database.openBusDatabase();
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ControllerInterface().setVisible(true);
            }
        });
    }

     @Override
     public void dispose()
     {
        System.out.println("Closing");
        database.busDatabase.close();
        super.dispose();
     }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton generateTimetableButton;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables

}
